package cn.bdqn.third;

/**
 * @Description TODO
 * @Date 2020/2/12 9:38
 * @Created by 张三三
 */
public class TextPaper implements Paper{

    private int charPerLine = 16;
    private int linePerPage = 5;

    public void setCharPerLine(int charPerLine) {
        this.charPerLine = charPerLine;
    }

    public void setLinePerPage(int linePerPage) {
        this.linePerPage = linePerPage;
    }

    private String content = "";
    private int posX = 0;
    private int posY = 0;
    private int posP = 1;


    public void putInChar(char c) {
        content += c;
        ++ posX;
        if (posX == charPerLine){
            content += Paper.newline;
            posX = 0;
            ++posY;
        }
        if(posY == linePerPage){
            content += "==第"+posP+"页===";
            content += Paper.newline + Paper.newline;
            posY = 0;
            ++posP;
        }
    }


    public String getContent() {
        String ret = this.content;

        if(!(posX == 0 && posY == 0)){
            int count = linePerPage - posY;
            for(int i = 0 ; i < count; ++i ){
                ret += Paper.newline;
            }
            ret += "==第"+posP+"页===";
        }
        return ret;
    }
}